import type { RouteRecordRaw } from 'vue-router'

export const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: () => import('@/layout/AppLayout.vue'),
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/Dashboard.vue'),
        meta: {
          title: '数据总览',
          icon: 'DataAnalysis',
          keepAlive: true,
          showInMenu: true
        }
      },
      {
        path: 'customers',
        name: 'Customers',
        component: () => import('@/views/customers/CustomerManagement.vue'),
        meta: {
          title: '客户管理',
          icon: 'User',
          keepAlive: true,
          showInMenu: true
        }
      },
      {
        path: 'customers/create',
        name: 'CustomerCreate',
        component: () => import('@/views/customers/CustomerForm.vue'),
        meta: {
          title: '新增客户',
          icon: 'User',
          keepAlive: false,
          showInMenu: false
        }
      },
      {
        path: 'customers/:id/edit',
        name: 'CustomerEdit',
        component: () => import('@/views/customers/CustomerForm.vue'),
        meta: {
          title: '编辑客户',
          icon: 'User',
          keepAlive: false,
          showInMenu: false
        }
      },
      {
        path: 'customers/:id',
        name: 'CustomerDetail',
        component: () => import('@/views/customers/CustomerDetail.vue'),
        meta: {
          title: '客户详情',
          icon: 'User',
          keepAlive: false,
          showInMenu: false
        }
      },
      {
        path: 'customers/unified/create',
        name: 'CustomerUnifiedCreate',
        component: () => import('@/views/customers/CustomerUnifiedForm.vue'),
        meta: {
          title: '新建客户档案（统一表单）',
          icon: 'User',
          keepAlive: false,
          showInMenu: false
        }
      },
      {
        path: 'customers/unified/:id/edit',
        name: 'CustomerUnifiedEdit',
        component: () => import('@/views/customers/CustomerUnifiedForm.vue'),
        meta: {
          title: '编辑客户档案（统一表单）',
          icon: 'User',
          keepAlive: false,
          showInMenu: false
        }
      },
      {
        path: 'sales',
        name: 'Sales',
        component: () => import('@/views/sales/SalesOpportunity.vue'),
        meta: {
          title: '销售机会',
          icon: 'Money',
          keepAlive: true,
          showInMenu: true
        }
      },
      {
        path: 'products',
        name: 'Products',
        component: () => import('@/views/products/ProductManagement.vue'),
        meta: {
          title: '产品管理',
          icon: 'Box',
          keepAlive: true,
          showInMenu: true
        }
      },
      {
        path: 'activities',
        name: 'Activities',
        component: () => import('@/views/activities/ActivityManagement.vue'),
        meta: {
          title: '邀约活动',
          icon: 'Calendar',
          keepAlive: true,
          showInMenu: true
        }
      },
      {
        path: 'tours',
        name: 'Tours',
        component: () => import('@/views/tours/TourManagement.vue'),
        meta: {
          title: '出团管理',
          icon: 'MapLocation',
          keepAlive: true,
          showInMenu: true
        }
      },
      {
        path: 'aftercare',
        name: 'Aftercare',
        component: () => import('@/views/aftercare/AftercareService.vue'),
        meta: {
          title: '售后服务',
          icon: 'Service',
          keepAlive: true,
          showInMenu: true
        }
      },
      {
        path: 'statistics',
        name: 'Statistics',
        component: () => import('@/views/statistics/DataStatistics.vue'),
        meta: {
          title: '数据统计',
          icon: 'TrendCharts',
          keepAlive: true,
          showInMenu: true
        }
      },
      {
        path: 'analysis',
        name: 'Analysis',
        component: () => import('@/views/analysis/CustomerAnalysis.vue'),
        meta: {
          title: '客户分析',
          icon: 'DataAnalysis',
          keepAlive: true,
          showInMenu: true
        }
      },
      {
        path: 'system',
        name: 'System',
        component: () => import('@/views/system/SystemManagement.vue'),
        meta: {
          title: '系统管理',
          icon: 'Setting',
          keepAlive: true,
          showInMenu: true
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login.vue'),
    meta: {
      title: '登录',
      hideInMenu: true,
      noAuth: true
    }
  },
  {
    path: '/404',
    name: 'NotFound',
    component: () => import('@/views/error/NotFound.vue'),
    meta: {
      title: '页面不存在',
      hideInMenu: true,
      noAuth: true
    }
  },
  {
    path: '/:pathMatch(.*)*',
    redirect: '/404'
  }
]

// 导出菜单路由（用于侧边栏生成）
export const menuRoutes = routes.filter(route => 
  route.meta?.showInMenu && !route.meta?.hideInMenu
)